package com.shine.icis.util;

public class Tools {
	public static String getFixedNum(long num, int length) {
		return getFixedLength(Long.toString(num), length, '0', true);
	}
	
	public static String getFixedLength(String str, int length, char fillChar, boolean left) {
		int sLength = str == null ? 0 : str.length();
		str = str == null ? "" : str;
		if (sLength > length) {
			throw new IllegalArgumentException("长度超出范围");
		} else if (sLength == length) {
			return str;
		}
		StringBuffer fillStr = new StringBuffer();
		for (int i = 0; i < length - sLength; i++) {
			fillStr.append(fillChar);
		}
		if (left) {
			return fillStr.toString() + str;
		} else {
			return str + fillStr.toString();
		}
	}
}
